#include "flGraphics.h"

/*
	Color related methods
*/
void flBackgroundColor(int r, int g, int b, int a)
{
	float rBG = (float)r/(float)255.;
	float gBG = (float)g/(float)255.;
	float bBG = (float)b/(float)255.;
	float aBG = (float)a/(float)255.;
	glClearColor(rBG, gBG, bBG, aBG);
}
void flSetColor(int r, int g, int b, int a)
{
	float rC = (float)r/(float)255.;
	float gC = (float)g/(float)255.;
	float bC = (float)b/(float)255.;
	float aC = (float)a/(float)255.;
	glColor4f(rC, gC, bC, aC);
}

/*
	Text method
*/
void flDrawText(string text, float x, float y)
{
	bool lightIsOn		= glIsEnabled(GL_LIGHTING);
	bool texture2DIsOn	= glIsEnabled(GL_TEXTURE_2D);
	bool depthTestIsOn	= glIsEnabled(GL_DEPTH_TEST);

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
		glLoadIdentity();
		gluOrtho2D(0,flGetWindowWidth(), flGetWindowHeight(), 0);
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
			glLoadIdentity();
			glPushAttrib(GL_ENABLE_BIT);
				
				if(lightIsOn)
					glDisable(GL_LIGHTING);
				if(texture2DIsOn)
					glDisable(GL_TEXTURE_2D);
				if(depthTestIsOn)
					glDisable(GL_DEPTH_TEST);

				glRasterPos3f(x, y, 0);

				char* s = (char*)text.c_str();
				if (s && strlen(s)) {
				  while (*s) {
					 glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *s);
					 s++;
				  }
				}


				if(lightIsOn)
					glEnable(GL_LIGHTING);
				if(texture2DIsOn)
					glEnable(GL_TEXTURE_2D);
				if(depthTestIsOn)
					glEnable(GL_DEPTH_TEST);
				
			glPopAttrib();
		glPopMatrix();
		glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
}